

var isSymmetric = function (root) {
    function compare(left, right) {
        if (right == null && left !== null) {
            return false;
        } else if (left == null && right !== null) {
            return false;
        } else if (left == null && right == null) {
            return true;
        } else if (left.val !== right.val) {
            return false;
        } else {
            return compare(left.left, right.right) && compare(left.right, right.left);
        }
    }
    return compare(root.left, root.right);
};